package com.whale.cloud.util;


import com.alibaba.fastjson.JSONObject;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Properties;

public class MessageHandlerUtil {
    public JSONObject getMessage(String message) {
        JSONObject mh = new JSONObject();
        String ts = String.valueOf(System.currentTimeMillis());
        HashMap<String, String> params = new HashMap<String, String>();
        JSONObject obj = JSONObject.parseObject(message);
        String userId = obj.getString("FromUserName");
        params.put("args[params]", message);
        params.put("format", "JSON");
        params.put("client", "");
        params.put("ver", "1.0");
        params.put("ts", ts);
        params.put("sig", this.getSign(ts, userId));

        try {
//            mh = HttpRequest.sendRequest("http://www.o2o.shoptao.cn/servlets/binserv/nds.weixinpublicparty.ext.BindDemo", params, "POST");
            //mh=HttpRequest.sendRequest("http://192.168.1.125:8080/servlets/binserv/AdminController_send.do",params,"POST");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return mh;
    }

    public String getSign(String ts, String userId) {
        InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("r.properties");
        Properties pts = new Properties();
        try {
            pts.load(inputStream);
        } catch (IOException e1) {
            e1.printStackTrace();
        }
        String sign = null;
        try {
            new MD5Util();
            sign = MD5Util.toCheckSumStr(userId + ts + pts.getProperty("skey"));
        } catch (IOException e) {
            e.printStackTrace();
        }
        return sign;
    }
}
